#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i  ,b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
const int N=1e6+9;
int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int n;
struct qwe{int to,id;};
vector<qwe>e[N];
int sz[N],rt,all=0;
long long ans[N],res;
int used[N];
int F[N],SZ[N];
int get(int x){return F[x]==x?x:F[x]=get(F[x]);}
void dfs(int x,int fa){
	sz[x]=1;used[x]=rt;int y;
	for(qwe to:e[x])if(to.to!=fa){
		y=to.to;dfs(y,x);
		ans[to.id]-=1ll*sz[y]*(all-sz[y]);
		sz[x]+=sz[y];
	}
}
int sta[20],top;
void write(long long x){
	do sta[++top]=x%10,x/=10;while(x);
	while(top)putchar(sta[top--]+'0');
	putchar('\n');
}
struct node{
	int x,y,w,id;
	bool operator<(const node&X)const{return w>X.w;}
}A[N];
signed main(){
//	system("fc tatooine.out tatooine4.out");return 0;
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	n=read();
	rep(i,n-1){
		A[i].x=read();
		A[i].y=read();
		A[i].w=read();
		A[i].id=i;
	}
	rep(i,n)F[i]=i,SZ[i]=1;
	sort(A+1,A+n);int j=1;
	long long ppp=0;
	Rof(k,20,1){
		while(j<=n-1&&A[j].w==k){
			e[A[j].x].push_back(qwe{A[j].y,A[j].id});
			e[A[j].y].push_back(qwe{A[j].x,A[j].id});
			int x=get(A[j].x),y=get(A[j].y);
			F[x]=y;SZ[y]+=SZ[x];
			j++;
		}
		res=0,rt=k;
		rep(i,n)if(used[i]!=rt){
			all=SZ[get(i)];dfs(i,0);
			res+=1ll*sz[i]*(sz[i]-1)/2;
		}
		ppp+=res;
	}assert(j==n);
	rep(i,n-1)write(ans[i]+ppp);
	return 0;
}

